import JSEncrypt from 'jsencrypt/bin/jsencrypt.min'

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQChe1Oy9WHiNmcW781HUo6FS6IlmVVpbBfbIo7F9M33VMBxQ8q0rtzy88u6tS9U7ZtPZ420xTAkVXxeyc7hki1IeQcTfIjkaas3XoXyr9Z8XXZOa6v9/fC2zSOwUz5CWCyPVhMesd1kk78Dn3x+e7Xj0Xd06mYNRwsvURdlZg8/twIDAQAB'

const privateKey = 'MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAKF7U7L1YeI2ZxbvzUdSjoVLoiWZVWlsF9sijsX0zfdUwHFDyrSu3PLzy7q1L1Ttm09njbTFMCRVfF7JzuGSLUh5BxN8iORpqzdehfKv1nxddk5rq/398LbNI7BTPkJYLI9WEx6x3WSTvwOffH57tePRd3TqZg1HCy9RF2VmDz+3AgMBAAECgYBBrge9IlFN0RLdIWw9NjcBwGGTKWq0FmMdnlCz835SuwYLC6fHFdiIeODEcC1wPbSN93CLtih+nsaXRz3+QZZo3mO9fdasDsWjEqI7JMWzH1tahnb41PLUuxshVtfxj26KhhSEKBgW1pCrT2YALeeLWIzKLNAzGJ5TmXbty4hMAQJBAM9F+N760tq1NXHKpC4I6mgXS0iVB2gflSTlnrB/nkwZEcNJoloEQK+Hhf9cRKPfT8yB6QIRj9fFFfADpnUaIEcCQQDHcYwAoGm1NNZb7n9N23o+/VeiJ0ISel+aQrZ+2jgbIkzRfXqIIksWi63f4f9Ctl/GCJMJky9KOk2z9AWaFI0RAkEAhp+F4x26Mb8cdUoOlK/Jv83RYdUZuHE653oUNcLNx9NIjDSZNCoq8Vbum0sMcfsq00NVWbiaWqRxeTCFvu03JQJBAJwI+Lhwx+LuEJrh75UxFeX7/LivMCEWvn8InJCIF4cbAbCQE/I3qjlcVE8pF7TQzAM6KBdAoKnZDXuxeUR/uZECQDl4xQpWh2l0r8wFFumUli3u39FBpDOpjqYYQ9oPJgHJz4eoct5eJjqE8PGFuUsUU+eFHEN/LjvitDtpM1P6df8='

// 加密
export function encrypt(txt) {
    const encryptor = new JSEncrypt()
    encryptor.setPublicKey(publicKey) // 设置公钥
    return encryptor.encrypt(txt) // 对数据进行加密
}

// 解密
export function decrypt(txt) {
    const encryptor = new JSEncrypt()
    encryptor.setPrivateKey(privateKey) // 设置私钥
    return encryptor.decrypt(txt) // 对数据进行解密
}